<template>
  <view class="address">
    <view style="height: 20rpx;"></view>

    <view class="pListlist">
      <view class="pListli">
        <view class="pListlileft">
          姓名
        </view>
        <input
          class="pListliinput"
          type="text"
          value=""
          v-model="pList.realname"
          placeholder="请填写姓名姓名"
          placeholder-style="font-size:28rpx;color:#9c9c9c;"
        />
      </view>
      <view class="pListli">
        <view class="pListlileft">
          证件类型
        </view>
        <view class="pListliinput">身份证</view>
      </view>
      <view class="pListli">
        <view class="pListlileft">
          证件号码
        </view>
        <input
          class="pListliinput"
          maxlength="18"
          value=""
          v-model="pList.IDNumber"
          placeholder="请填写证件号码"
          placeholder-style="font-size:28rpx;color:#9c9c9c;"
        />
      </view>
      <view class="pListli">
        <view class="pListlileft">
          手机号码
        </view>
        <input
          class="pListliinput"
          maxlength="11"
          type="number"
          value=""
          v-model="pList.telephone"
          placeholder="请填写手机号码"
          placeholder-style="font-size:28rpx;color:#9c9c9c;"
        />
      </view>
    </view>
    <view
      class="saveaddress btn-class-w-h"
      @tap="saveinfo"
    >
      保存
    </view>
  </view>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      pList: {
        realname: '',
        telephone: '',
        IDNumber: '',
      },
    }
  },
  onLoad: function (option) {
    // 如果存在则为修改接口，否则为新增地址，且新增时默认回显用户名等个人信息
    if (option.obj) {
      this.pList = option.obj
      var pList = decodeURIComponent(option.obj)
      this.pList = JSON.parse(pList)
    }
  },
  methods: {
    //保存地址
    saveinfo() {
      var that = this
      if (!this.pList.realname) {
        uni.showToast({
          icon: 'none',
          title: '请输入姓名!',
        })
        return false
      }
      if (!this.pList.IDNumber) {
        uni.showToast({
          icon: 'none',
          title: '请输入身份证号!',
        })
        return false
      }
      if (!this.$publicFun.regIdCard(this.pList.IDNumber)) {
        uni.showToast({
          icon: 'none',
          title: '请输入正确的身份证号!',
        })
        return false
      }
      if (!this.$publicFun.regPhone.test(this.pList.telephone)) {
        uni.showToast({
          icon: 'none',
          title: '请输入正确的手机号!',
        })
        return false
      }
      var data = {}
      this.addAddressApi()
    },
    //添加观影人
    async addAddressApi() {
      var that = this
      const data = await this.$apiFun.postApi(
        this.$api.createOrUpdateContactsApi,
        this.pList
      )
      uni.showToast({
        icon: 'none',
        title: '保存成功！',
      })
      setTimeout(() => {
        uni.navigateBack()
      }, 2000)
      this.$bus.$emit('refreshPeople')
    },
  },
}
</script>
<style>
page {
  height: 100%;
  background: #000000;
  color: white;
}
</style>
<style scoped lang="less">
page {
  background-color: #000000;
}
.address {
  height: auto;
}
.pListlist {
}
.pListli {
  background-color: rgba(255, 255, 255,.1);
  padding: 0 30rpx;
  box-sizing: border-box;
  display: flex;
  margin-bottom: 10rpx;
}
.pListli:last-child {
  border-bottom: none;
}
.pListlileft {
  width: 160rpx;
  height: 98rpx;
  line-height: 98rpx;
  font-size: 28rpx;
  color: rgba(255, 255, 255,1);
}
.pListliinput {
  width: 560rpx;
  height: 98rpx;
  line-height: 98rpx;
  font-size: 28rpx;
  color: rgba(255, 255, 255,1);
}
.pListli .right {
  padding-right: 15rpx;
  box-sizing: border-box;
  // background: url('@{imgUrl}godtail.png') no-repeat right;
  background-position-y: center;
  background-size: 12rpx 22rpx;
}
.pListlione {
  padding: 25rpx 30rpx;
}
.pListlione .pListlileft {
  line-height: 48rpx;
}
.pListlitextarea {
  font-size: 28rpx;
  color: #9c9c9c;
  height: 180rpx;
  box-sizing: border-box;
  padding: 0;
}
.pListdefault {
  width: 620rpx;
}
.deladdress {
  margin-top: 4rpx;
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  background-color: #ffd8d6;
  font-size: 28rpx;
  color: #ec453d;
  text-align: center;
}
.saveaddress {
  line-height: 80rpx;
  text-align: center;
  background: linear-gradient(to right, #ff7a81, #fd2f79);
  font-size: 30rpx;
  color: #ffffff;
  position: fixed;
  left: 5%;
  right: 0;
  bottom: 30rpx;
  width: 90%;
  height: 40px;
}
</style>
